package example.simple_mindmap.controller;

import example.simple_mindmap.common.annotation.Log;
import example.simple_mindmap.common.domain.po.Result;
import example.simple_mindmap.domain.po.MindMap;
import example.simple_mindmap.service.EsServiceImpl;
import example.simple_mindmap.service.MindMapServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @BelongsProject: chatgpt-java-develop
 * @BelongsPackage: com.unfbx.controller
 * @Author : 游在海里的鱼
 * @CreateTime : 2024-03-20  20:12
 * @Version : 1.0
 * @ClassName :  导图控制器
 * @Description : TODO
 */
@Slf4j
@RestController
@Api(tags = "导图相关接口")
@RequestMapping("/mindMap")
@RequiredArgsConstructor
public class MindMapController {

    private final MindMapServiceImpl mindMapService;
    private final EsServiceImpl esService;


    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 新增导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="新增导图")
    @ApiOperation("新增导图")
    @GetMapping("/addMindMap")
    public Result addMindMap(){
        return mindMapService.addMindMap();
    }
    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 编辑导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="编辑导图")
    @ApiOperation("编辑导图")
    @PostMapping("/editMindMap")
    public Result editMindMap(MindMap mindMap){
        return mindMapService.editMindMap(mindMap);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 删除导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="删除导图")
    @ApiOperation("删除导图")
    @GetMapping("/deleteMindMap")
    public Result deleteMindMap(@RequestParam("id")Long id){
        return mindMapService.deleteMindMap(id);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 分页获取公开的所有导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="分页获取所有公开导图")
    @ApiOperation("分页获取所有公开导图")
    @GetMapping("/getPublicMindMap")
    public Result getPublicMindMap(@RequestParam("page")Integer page){
        return mindMapService.getPublicMindMap(page);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 获取此用户的所有导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="分页获取用户导图")
    @ApiOperation("分页获取用户导图")
    @GetMapping("/getUserMindMap")
    public Result getUserMindMap(@RequestParam("page")Integer page){
        return mindMapService.getUserMindMap(page);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 获取此用户的所有公开导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="分页获取用户公开导图")
    @ApiOperation("分页获取用户公开导图")
    @GetMapping("/getPublicMindMapByUid")
    public Result getPublicMindMapByUid(Integer page,Long uid){
        return mindMapService.getUserPublicMindMap(uid,page);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 获取导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="获取导图")
    @ApiOperation("获取导图")
    @GetMapping("/getMindMapById")
    public Result getMindMapById(@RequestParam("mindMapId")Long mindMapId){
        return mindMapService.getMindMapById(mindMapId);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 检查此用户的导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="检查导图")
    @ApiOperation("检查导图")
    @GetMapping("/checkMindMapByTitle")
    public Result checkMindMapByTitle(Long mid){
        return mindMapService.checkMindMapByTitle(mid);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 置顶导图
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="置顶导图")
    @ApiOperation("置顶导图")
    @PostMapping("/setTop")
    public Result setTop(@RequestParam("mindMapId")Long mindMapId){
        return mindMapService.setTop(mindMapId);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 发送图片
     * @Describe: TODO
     * @modifier: [public] [实例方法]
    **/
    @Log(name="发送图片")
    @ApiOperation("发送图片")
    @PostMapping("/sendImage")
    public Result sendImage(@RequestParam("guid") Long mid,
                            @RequestParam("editormd-image-file") MultipartFile image){
        return mindMapService.sendImage(mid,image);
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 发送导图封面图片
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="发送导图头图片")
    @ApiOperation("发送导图头图片")
    @PostMapping("/sendRootImage")
    public Result sendRootImage(@RequestParam("mindMapId") Long mid,
                            @RequestParam("mindMap-image-file") MultipartFile image){
        return mindMapService.sendRootImage(mid,image);
    }
    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : ES初始化
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="ES初始化")
    @ApiOperation("ES初始化")
    @PostMapping("/initES")
    public Result initES() throws IOException {
        return esService.init();
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 搜索
     * @Describe: TODO
     * @modifier: [public] [实例方法]
     **/
    @Log(name="搜索")
    @ApiOperation("搜索")
    @GetMapping("/search")
    public Result search(String search,Integer page) throws IOException {
        return esService.searchES(search,page);
    }

    @Log(name="添加数据")
    @ApiOperation("添加数据")
    @GetMapping("/adds")
    public Result adds(){

        return mindMapService.adds();
    }
}
